#ifndef TETRIXSERVER_H
#define TETRIXSERVER_H

#include <QtGlobal>
#include <QString>
#include <ace/SOCK_Stream.h>
#include <ace/SOCK_Acceptor.h>
#include <ace/Handle_Set.h>
#include <map>
#include <iostream>
#include <stdlib.h>
#include <string.h>
#include "roommanager.h"
#include "protosrvmanager.h"

class TetrixServer
{
public:
    static std::auto_ptr<TetrixServer> &getInstance();

    virtual ~TetrixServer();
    bool run(int argc,char *argv[]);
    void stop() { _stop = true;}
    void remove(ACE_SOCK_Stream& peer);

    bool broadcast(std::auto_ptr<SimpleProtoSrv> &msg);
protected:
    TetrixServer() : _stop(false) {}

    virtual bool    open(quint16 port);
    virtual bool    wait_for_multi_events();
    virtual bool    handle_connections();
    virtual bool    handle_data();
private:
    bool                _stop;
    ACE_Handle_Set      _master_set;
    ACE_Handle_Set      _active_set;
    ACE_SOCK_Acceptor   _acceptor;

    static std::auto_ptr<TetrixServer> _instance;
};

#endif // TETRIXSERVER_H
